import store from '@/store'
window.buttonPermission=function(key) {
  var url=window.location.hash.replace("#/","").split('/'),
      first="/"+url[0],
      two=url[1]+"/"+url[2].split('?')[0],
      rolesList=store.getters.menuList,
      hasBool=false;
  rolesList.some((val0)=>{
  	if(val0.menuName){
  	 	hasBool= true;
        return true;
    }else{
      	val0.childrenMenuList.some((val)=>{
            if(val.menuUrl==first&&!hasBool){
		     	val.childrenMenuList.some((val1)=>{
		     		if(val1.routeUrl==two&&!hasBool){
		     			val1.menuPermissionList.some((val2)=>{
		                    if(val2.permissionKey==key){
		                    	hasBool= true;
		                    	return true;
		                    }
		     			})
		     		}
		     	})
		    }
      	})
      }
  });
  return hasBool;
};

/*window.buttonPermission1=function(key) {
  debugger
  var url=window.location.hash.replace("#/","").split('/'),
      first="/"+url[0],
      two=url[1]+"/"+url[2].split('?')[0],
      rolesList=store.getters.menuList,
      hasBool=false;
  for(let i=0;i<rolesList.length;i++){
    if(rolesList[i].menuName){
      if( Object.prototype.toString.call(key) === '[object Array]'){
        hasBool=[];
        hasBool=key.filter((item)=>{
            return true;
        })
      }else{
        hasBool=true;
      }
    }else{
       console.log(1)
    }
  }



  rolesList.some((val0)=>{
    if(val0.menuName){
      hasBool= true;
        return true;
    }else{
        val0.childrenMenuList.some((val)=>{
            if(val.menuUrl==first&&!hasBool){
          val.childrenMenuList.some((val1)=>{
            if(val1.routeUrl==two&&!hasBool){
              val1.menuPermissionList.some((val2)=>{
                        if(val2.permissionKey==key){
                          hasBool= true;
                          return true;
                        }
              })
            }
          })
        }
        })
      }
  });
  return hasBool;
};


window.buttonPermission2=function(key) {
  var url=window.location.hash.replace("#/","").split('/'),
      first="/"+url[0],
      two=url[1]+"/"+url[2].split('?')[0],
      rolesList=store.getters.menuList,
      hasBool=false;
  rolesList.some((val0)=>{
    if(val0.menuName){
      if( Object.prototype.toString.call(key) === '[object Array]'){
        hasBool= [];
        for(let j=0;j<key.length;j++){
          hasBool.push(true);
        }
        return
      }else{
        hasBool=true;
        return
      }
    }else{
      val0.childrenMenuList.some((val)=>{
        if(val.menuUrl==first){
          val.childrenMenuList.some((val1)=>{
            if(val1.routeUrl==two){
              val1.menuPermissionList.some((val2)=>{
                debugger
                if(key.isArray()){
                  hasBool=[];
                  for(let i=0;i<key.length;i++){
                     if(val2.permissionKey==key){
                        hasBool.push(true);
                      }
                    return
                  }
                }else{
                  if(val2.permissionKey==key){
                    hasBool= true;
                    return
                  }
                }
              })
            }
          })
        }
      })
    }
  });
  return hasBool;
}*/